/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-06-12
 * Time: 16:23
 */
public class Test3 {
    //实现该方法-- 获取数组的元素
    public static int getElement(int[] array, int index){
        if(array == null){
            //抛出异常
            throw new NullPointerException("数组为空");
        }

        if(index < 0 || index >= array.length){
            //抛出异常
            throw new ArrayIndexOutOfBoundsException("数组下标越界");
        }
        return array[index];
    }
    public static void main(String[] args) {
        //1.数组越界情况
        int[] array1 = {1,2,3};
        getElement(array1, 3);
        //2.数组为空情况
        //int[] array2 = null;
        //getElement(array2,0);
        //3.正常情况
        //getElement(array1,1);

    }
}
